package com.auanaum.dao.impl;

import java.util.List;

import javax.jdo.PersistenceManager;

import org.springframework.stereotype.Repository;

import com.auanaum.dao.MovieDao;
import com.auanaum.dto.Movie;
import com.auanaum.persistence.PMF;

@Repository
public class MovieDaoImpl implements MovieDao{

	
	@Override
	public void create(Movie movie){
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try{
			pm.makePersistent(movie);
		} finally{
			pm.close();
		}
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Movie> findAll() {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		List<Movie> movies;
		try {
			String query = "select from " + Movie.class.getName();
			movies = (List<Movie>) pm.newQuery(query).execute();
	
			movies.size(); // XXX: see above

			return movies;
		} finally {
			pm.close();
		}
	}
}
